﻿namespace WMS6.Web.Administration
{
    using System;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.LoginServiceRef;

    public class ChangePwd : BasePage
    {
        protected Button btnCancel;
        protected Button btnOK;
        protected HtmlForm F1040;
        protected HtmlInputHidden hdnActionID;
        protected Label lblChangePwd;
        protected Label lblConfirmPassword;
        protected Label lblMsg;
        protected Label lblNewPassword;
        protected Label lblOldPassword;
        protected HtmlLink mycss;
        protected TextBox txtConfirmPassword;
        protected TextBox txtNewPassword;
        protected TextBox txtOldPassword;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtOldPassword.Text = "";
            this.txtNewPassword.Text = "";
            this.txtConfirmPassword.Text = "";
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtOldPassword.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F1400_001");
            }
            else if (string.IsNullOrEmpty(this.txtNewPassword.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F1400_002");
            }
            else if (string.IsNullOrEmpty(this.txtConfirmPassword.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F1400_003");
            }
            else
            {
                try
                {
                    string oldPwd = this.txtOldPassword.Text.Trim();
                    string newPwd = this.txtNewPassword.Text.Trim();
                    string confimrPwd = this.txtConfirmPassword.Text.Trim();
                    WMS6.Web.BaseInfoServiceRef.UserMstInfo userInfo = new WMS6.Web.BaseInfoServiceRef.UserMstInfo();
                    WMS6.Web.LoginServiceRef.PreferenceInfo originPreference = base.UserInfo.Preference;
                    userInfo = base.TurnUserInfo(base.UserInfo);
                    if (oldPwd != userInfo.Passwd)
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F1400_004");
                    }
                    else if (newPwd != confimrPwd)
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F1400_005");
                    }
                    else
                    {
                        userInfo.Passwd = newPwd;
                        userInfo.UpdatedBy = userInfo.UserID;
                        userInfo.ExpireDate = DateTime.Now.AddMonths(3);
                        if (!string.IsNullOrEmpty(BaseInfoServiceClientProxy.GetInstance().Update(userInfo, "USER_MST")))
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F1400_006");
                            base.UserInfo = base.TurnUserInfo(userInfo);
                            base.UserInfo.Preference = originPreference;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
            }
        }
    }
}

